package com.huifaapp.mall.activity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;
import android.widget.Toast;

import com.blankj.utilcode.util.ClipboardUtils;
import com.blankj.utilcode.util.SPUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.bumptech.glide.Glide;
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import com.huifaapp.mall.R;
import com.huifaapp.mall.adapter.Shoppingcart1popwinAdapter;
import com.huifaapp.mall.adapter.Shoppingcart2popwinAdapter;
import com.huifaapp.mall.afinal.SPConstants;
import com.huifaapp.mall.api.ApiManager;
import com.huifaapp.mall.bean.AddeollectBean;
import com.huifaapp.mall.bean.Goods;
import com.huifaapp.mall.bean.ShoppingCartGuigeBean;
import com.huifaapp.mall.bean.WebJDShare;
import com.huifaapp.mall.bean.YouhuiParticularsBean;
import com.huifaapp.mall.bean.parmQueryBean;
import com.huifaapp.mall.fragment.EvaluateFragment;
import com.huifaapp.mall.fragment.SpecificationsFramgnet;
import com.huifaapp.mall.uitils.AUniqueIdentifier;
import com.huifaapp.mall.uitils.Contig;
import com.huifaapp.mall.uitils.CustomViewPager;
import com.huifaapp.mall.uitils.GlideImageLoader;
import com.huifaapp.mall.uitils.NoScrollGridView;
import com.huifaapp.mall.view.AmountView;
import com.huifaapp.mall.view.PullUpToLoadMore;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest;
import com.squareup.okhttp.Request;
import com.squareup.picasso.Picasso;
import com.umeng.socialize.ShareAction;
import com.umeng.socialize.UMShareListener;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.media.UMImage;
import com.umeng.socialize.media.UMWeb;
import com.youth.banner.Banner;
import com.youth.banner.BannerConfig;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.just.library.AgentWebUtils.dismiss;


/**
 * Created by 段昱 on 2017/12/14.
 */

public class ShoppingCartActivity extends AppCompatActivity {

    private TabLayout particulars_tab;
    private CustomViewPager particulars_viewPager;
    private List<Fragment> fragmentList;
    private ParticularsIntroduceFragment particularsIntroduceFragment;
    private SpecificationsFramgnet specificationsFramgnet;
    private EvaluateFragment evaluateFragment;
    private List<String> stringList;
    private LinearLayout shoppingCartactivity_coupon;
    private ImageView imge1;
    private PopupWindow mPopWindow;
    private LinearLayout accomplish;
    private View.OnKeyListener onKeyListener;
    private LinearLayout shoppingCartactivity__event;
    private LinearLayout shoppingCartactivity__parameter;
    private PopupWindow parameterPopWindow;
    private View.OnKeyListener parameteronKeyListener;
    private LinearLayout parameter_close1;
    private PopupWindow mEventPopWindow;
    private ImageView event_imge;
    private View.OnKeyListener onEventKeyListener;
    private View.OnKeyListener onEventKeyListener1;
    private View.OnKeyListener onShareKeyListener;
    private List<String> colourlist;
    private ImageView shoppingbutten_share;
    private PopupWindow mSharePopWindow;
    private ImageView share_imge;
    private Banner youhuiParticulars_banner;
    private List<String> bannerimgeList;
    private TextView youhuiParticulars_goodsName;
    private TextView youhuiParticulars_price;
    private TextView youhuiParticulars_priceconPrice;
    private TextView youhuiParticulars_wlCommission;
    private TextView youhuiParticulars_totalSales;
    private TextView youhuiParticulars_isFreePost;
    private ImageView youhuiParticulars_bannerTip;
    private ImageView youhuiParticulars_bannerTip2;
    private List<YouhuiParticularsBean.DataBean.DetailPropergoryBean> propertysBeanlist;
    private RecyclerView popouplayout_event_parameter_tyoe;
    private List<String> namelist;
    private List<Map<String, List<YouhuiParticularsBean.DataBean.DetailPropergoryBean>>> propertysBeanmap;
//    private LinearLayout popouplayout_event_parameter_tyoe1;
    private HashMap<String, List<YouhuiParticularsBean.DataBean.DetailPropergoryBean>> zDmap;
    private LinearLayout layout;
    private LinearLayout linearLayout;
    private LinearLayout cclinearLayout;
    private YouhuiParticularsBean youhuiParticularsBean;
    private YouhuiParticularsBean.DataBean data;
    private List<TextView> buttenlist;
    public String commodityid;
    private LinearLayout popouplayout_event_purchase;
    private PullUpToLoadMore ptlm;
    private ImageView popup_layout_skuDetails;
    private String skuDetails;
    private TextView popup_layout_skuDetailsskuPrice;
    private TextView popup_layout_totalInventory;
    private  String shopid;
    private  String typex;
    private parmQueryBean parmQueryBean;
    private  int count=1;
    private LinearLayout popouplayout_event_addshoppingcart;
    private String spuId;
    private String etailImagess;
    private android.app.FragmentTransaction transaction;
    private android.app.FragmentManager manager;
    private String detailImagesstr;
    private LinearLayout shoppingCartactivity_include_tab,shoppingCartactivity_include_tab_yure;
    private TextView popup_layout_size;
    private TextView popup_layout_colour;
    private RecyclerView tamll_popuplayout_reds_recyclerView;
    private  String INFOURL=ApiManager.BASE_HTML_URL+"coupon/info";
    private String ADDEOLLECTURL=ApiManager.BASE_NIUPAI_URL+"users/addcollect";
    private   ArrayList<String> listSkuidCount=new ArrayList<>();
    private LinearLayout youhuiParticulars_wlCommission_g;
    private WebJDShare list;
    boolean flag=false;
    private String Isspceial="立即抢购";
    private LinearLayout ll_shoppingcart_qunhou;
    private TextView tv_pop_event_title;
    private NoScrollGridView gv_pop_event_name;
    private TextView tv_pop_event_title2;
    private NoScrollGridView gv_pop_event_name2;
    private Shoppingcart1popwinAdapter adapter1;
    private Shoppingcart2popwinAdapter adapter2;
    ArrayList<String >  value1=new ArrayList<String>();
    ArrayList<String >  value2=new ArrayList<String>();
    ArrayList<String >  listid1=new ArrayList<String>();
    ArrayList<String >  listid2=new ArrayList<String>();
    private List<ShoppingCartGuigeBean> arr;
    private String id1;
    private String id2;
    ArrayList<String> lsid1=new ArrayList<>();
    ArrayList<String> lsid2=new ArrayList<>();
    ArrayList<String >  bg1=new ArrayList<String>();
    ArrayList<String >  bg2=new ArrayList<String>();
    ArrayList<String> goodskuParamQuery=new ArrayList<String>();
    private String querid;

    protected void onCreate(Bundle savedInstanceState) {
        setContentView(R.layout.activity_shoppingcart);
        super.onCreate(savedInstanceState);
        shopid=getIntent().getStringExtra("shopid");
        Isspceial = getIntent().getStringExtra("Isspceial");
        if("".equals(Isspceial)){
            Isspceial="立即抢购";
        }

        LoadWebJDShare();
        Log.e("TTTTTTTTTTTTTTTTTTTTT",shopid);
        typex=getIntent().getStringExtra("typex");
        initView();
        inityouhuiParticularsHttp();
        initTab();
        shoppingCartactivity_coupon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                CouponpopWindow();
            }


        });
        shoppingCartactivity__event.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                EventpopWindow();
            }
        });
    }

    private void inityouhuiParticularsHttp() {
        Log.e("详情", ApiManager.BASE_NIUPAI_URL + typex + "/detail" + "?id=" + shopid);
        OkHttpUtils.post().addParams("id",shopid).url( ApiManager.BASE_NIUPAI_URL+typex+"/detail").build()
                .execute(new StringCallback() {
                    private YouhuiParticularsBean.DataBean.DetailPropergoryBean propertysBean;
                    private HashMap<String, String> namemap;
                    @Override
                    public void onError(Request request, Exception e) {

                    }

                    @Override
                    public void onResponse(String response) {
                        Log.e("详情页全部数据", response);
                        Gson gson = new Gson();

                        youhuiParticularsBean = gson.fromJson(response, YouhuiParticularsBean.class);


                        if (youhuiParticularsBean.getCode().equals("10000")) {
                            data = youhuiParticularsBean.getData();
                            Bundle bundle = new Bundle();
                            String strValue = shopid;
                            bundle.putString("shopid", strValue);
                            Log.e("详情h5页面goods", strValue);
                            bundle.putString("spuImageUrl", data.getSpuImageUrl());
                            Log.e("详情h5页面", data.getSpuImageUrl());

                            particularsIntroduceFragment.setArguments(bundle);
                            specificationsFramgnet.setArguments(bundle);
                            evaluateFragment.setArguments(bundle);
                            bannerimgeList = new ArrayList<String>();
                            bannerimgeList.addAll(data.getBanner());
                            BannerData();
                            youhuiParticulars_goodsName.setText(data.getGoodsName());
                            youhuiParticulars_price.setText(data.getPrice() + "");
                            youhuiParticulars_priceconPrice.setText(data.getConPrice() + "");
                            youhuiParticulars_wlCommission.setText(data.getWlCommission() + "");
                            youhuiParticulars_totalSales.setText(data.getTotalSales() + "");
                            if (data.getIsFreePost().equals("1")) {
                                youhuiParticulars_isFreePost.setText("免运费");
                            } else {
                                youhuiParticulars_isFreePost.setText("邮费20元");
                            }
                            Glide.with(ShoppingCartActivity.this).load(data.getBannerTip()).into(youhuiParticulars_bannerTip);
                            Glide.with(ShoppingCartActivity.this).load(data.getBuyTip()).into(youhuiParticulars_bannerTip2);



                            youhuiParticularsBean.getData().getPropertys();

//                            //详情页购买选择数据
//                            ShoppingCartActivity.this.propertysBeanlist = new ArrayList<YouhuiParticularsBean.DataBean.DetailPropergoryBean>();
//                            ShoppingCartActivity.this.propertysBeanlist.addAll(youhuiParticularsBean.getData().getDetailPropergory());
//                            Log.e("propertysBeanlist的长度", propertysBeanlist.size() + "");
//                            propertysBean = new YouhuiParticularsBean.DataBean.DetailPropergoryBean();
//                            namelist = new ArrayList<String>();
//                            propertysBeanmap = new ArrayList<Map<String, List<YouhuiParticularsBean.DataBean.DetailPropergoryBean>>>();
//                            for (int i = 0; i < ShoppingCartActivity.this.propertysBeanlist.size(); i++) {
//                                if (namelist.contains(ShoppingCartActivity.this.propertysBeanlist.get(i).getName())) {
//                                    continue;
//                                }
//                                namelist.add(ShoppingCartActivity.this.propertysBeanlist.get(i).getName());
//                            }
//                            Log.e("namelist的长度", namelist.size() + "");
//                            for (int i = 0; i < namelist.size(); i++) {
//                                List<YouhuiParticularsBean.DataBean.PropertysBean> Stringvalue = new ArrayList<>();
//                                zDmap = new HashMap<String, List<YouhuiParticularsBean.DataBean.PropertysBean>>();
//
//                                for (int j = 0; j < propertysBeanlist.size(); j++) {
//                                    if (namelist.get(i).equals(propertysBeanlist.get(j).getName())) {
//                                        Stringvalue.add(propertysBeanlist.get(j));
//                                    }
//                                }
//                                zDmap.put(namelist.get(i), Stringvalue);
//                                propertysBeanmap.add(zDmap);
//                                Log.e("222222222", propertysBeanmap.size() + "");
//                            }
                        }else{
                            Toast.makeText(ShoppingCartActivity.this,youhuiParticularsBean.getMsg(),Toast.LENGTH_SHORT).show();
                        }
                    }
                });

    }



    private void BannerData() {
        youhuiParticulars_banner.setImageLoader(new GlideImageLoader());
        //设置图片集合
        youhuiParticulars_banner.setImages(bannerimgeList);
        youhuiParticulars_banner.setBannerStyle(BannerConfig.NUM_INDICATOR);
        //banner设置方法全部调用完毕时最后调用
        youhuiParticulars_banner.start();
    }

    private void parameterWindow() {
        View EventcontentView = LayoutInflater.from(ShoppingCartActivity.this).inflate(R.layout.popuplayout_parameter, null);
        parameterPopWindow = new PopupWindow(EventcontentView, ViewPager.LayoutParams.MATCH_PARENT, ViewPager.LayoutParams.WRAP_CONTENT, true);
        parameterPopWindow.setContentView(EventcontentView);
        parameter_close1 = (LinearLayout) EventcontentView.findViewById(R.id.parameter_accomplish);
        parameter_close1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(ShoppingCartActivity.this, "完成", Toast.LENGTH_SHORT).show();
                parameterPopWindow.dismiss();
            }
        });
        parameterPopWindow.setFocusable(true);
        parameterPopWindow.setBackgroundDrawable(new BitmapDrawable());
        // 然后再设置它的键监听器
        EventcontentView.setOnKeyListener(parameteronKeyListener);
        parameteronKeyListener = new View.OnKeyListener() {
            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                if(keyCode==KeyEvent.KEYCODE_BACK){
                    dismiss();
                    return true;
                }

                return false;
            }
        };
        //显示PopupWindow
        View parameteronrootview = LayoutInflater.from(ShoppingCartActivity.this).inflate(R.layout.activity_shoppingcart, null);
        parameterPopWindow.showAtLocation(parameteronrootview, Gravity.BOTTOM, 0, 0);
    }

    private void EventpopWindow() {
        Log.e("shoppingCartActivity","shoppingCartActivity==="+ ApiManager.BASE_NIUPAI_URL+typex+"/detail"+"?id="+shopid);
        View popuplayout_event = LayoutInflater.from(ShoppingCartActivity.this).inflate(R.layout.popuplayout_event, null);
        mEventPopWindow = new PopupWindow(popuplayout_event, ViewPager.LayoutParams.MATCH_PARENT, ViewPager.LayoutParams.WRAP_CONTENT, true);
        mEventPopWindow.setContentView(popuplayout_event);
        event_imge = (ImageView) popuplayout_event.findViewById(R.id.event_imge);
        popup_layout_skuDetails = (ImageView)popuplayout_event.findViewById(R.id.popup_layout_skuDetails);
//        popouplayout_event_parameter_tyoe1 = (LinearLayout) popuplayout_event.findViewById(R.id.popouplayout_event_parameter_tyoe);
        popouplayout_event_purchase = (LinearLayout) popuplayout_event.findViewById(R.id.popouplayout_event_purchase);
        popup_layout_skuDetailsskuPrice = (TextView) popuplayout_event.findViewById(R.id.popup_layout_skuDetailsskuPrice);
        popup_layout_totalInventory = (TextView)popuplayout_event. findViewById(R.id.popup_layout_totalInventory);
        popup_layout_skuDetails = (ImageView) popuplayout_event.findViewById(R.id.popup_layout_skuDetails);
        popouplayout_event_addshoppingcart= (LinearLayout) popuplayout_event.findViewById(R.id.popouplayout_event_addshoppingcart);
        popup_layout_size = (TextView) popuplayout_event.findViewById(R.id.popup_layout_size);
        popup_layout_colour = (TextView) popuplayout_event.findViewById(R.id.popup_layout_colour);
        tv_pop_event_title = (TextView) popuplayout_event.findViewById(R.id.tv_pop_event_title);
        gv_pop_event_name = (NoScrollGridView) popuplayout_event.findViewById(R.id.gv_pop_event_name);
        tv_pop_event_title2 = (TextView) popuplayout_event.findViewById(R.id.tv_pop_event_title2);
        gv_pop_event_name2 = (NoScrollGridView) popuplayout_event.findViewById(R.id.gv_pop_event_name2);
        OkHttpUtils.post().addParams("id",shopid).url( ApiManager.BASE_NIUPAI_URL+typex+"/detail").build().execute(new StringCallback() {
            @Override
            public void onError(Request request, Exception e) {

            }
            @Override
            public void onResponse(String response) {
                Log.e("详情按钮",response);
                Gson gson=new Gson();
                final YouhuiParticularsBean parmQueryBean = gson.fromJson(response, YouhuiParticularsBean.class);
                Log.e("详情按钮",parmQueryBean.toString());
                Log.e("详情", ApiManager.BASE_NIUPAI_URL+typex+"/detail"+"?id="+shopid);
                YouhuiParticularsBean.DataBean.DetailPropergoryBean detailPropergory = parmQueryBean.getData().getDetailPropergory();
                if (detailPropergory.getSkuDetails().equals("")){

                }else {
                    Picasso.with(ShoppingCartActivity.this)
                            .load(detailPropergory.getSkuDetails())
                            .into(popup_layout_skuDetails);
                }

                popup_layout_skuDetailsskuPrice.setText( detailPropergory.getSkuPrice()+"");
                popup_layout_totalInventory.setText(detailPropergory.getTotalInventory()+"");

try {
    Log.e("详情规格", parmQueryBean.getData().getPropertys() + "");
//    for(int i = 0; i < parmQueryBean.getData().getPropertys().length();i++) {  
//    JSONObject temp = (JSONObject) parmQueryBean.getData().getPropertys().get(i);  
//    String id = temp.getString("id");  
//    String id = temp.getString("version");  
//

    parmQueryBean.getData().getGoodsSku();

    value1.clear();
    value2.clear();
    listid1.clear();
    listid2.clear();
    arr = parmQueryBean.getData().getPropertys();
    for(int i = 0; i< arr.size(); i++){
        Log.e("详情规格", parmQueryBean.getData().getPropertys().get(i).getName() + "====adkgaoifdjaioodjiasdjiofjasidjf");
        if(arr.get(i).getName().equals( parmQueryBean.getData().getPropertys().get(0).getName())){
            value1.add(arr.get(i).getValue());
            listid1.add(arr.get(i).getId());
            tv_pop_event_title.setText(arr.get(i).getName());
            adapter1 = new Shoppingcart1popwinAdapter(value1,ShoppingCartActivity.this);
            gv_pop_event_name.setAdapter(adapter1);

            Log.e("详情规格", value1 + "====value");
        }else{
            value2.add(arr.get(i).getValue());
            listid2.add(arr.get(i).getId());
            tv_pop_event_title2.setText(arr.get(i).getName());
            Log.e("详情规格", value2 + "====value2");
            adapter2 = new Shoppingcart2popwinAdapter(value2,ShoppingCartActivity.this);
            gv_pop_event_name2.setAdapter(adapter2);
        }
    }

    adapter1.setmMyItemclickListener(new Shoppingcart1popwinAdapter.MypopItemclickListener() {
        @Override
        public void itemclick(View view, int position) {
            bg2.clear();
            lsid1.clear();
            for(int a=0;a<arr.size();a++){
                if(arr.get(a).getValue().equals(value1.get(position))){
                    Log.e("详情点击获取id",arr.get(a).getId()+"       "+value1.get(position));
                    popup_layout_colour.setText(arr.get(a).getValue());
                    id1=arr.get(a).getId();
                    lsid1.add(id1);
                    for (int t=0;t<lsid1.size();t++){
                        for (int y=0;y<lsid2.size();y++){
                            Log.e("详情id对比","id对比========"+lsid1.get(t)+":"+lsid2.get(y));
                        }
                    }

//                  Log.e("详情id对比","id对比========"+id1+":"+id2);
                    Log.e("详情GoodsSku","GoodsSku========"+parmQueryBean.getData().getGoodsSku());
//                    for(int u=0;u<value1.size();u++) {
//                        if (arr.get(a).getValue().equals(value1.get(u))) {
//                            for (int k = 0; k < parmQueryBean.getData().getGoodsSku().size(); k++) {
//                                goodskuParamQuery.add(parmQueryBean.getData().getGoodsSku().get(k).getParamQuery());
//                                for (int p = 0; p < goodskuParamQuery.size(); p++) {
//                                    if (goodskuParamQuery.get(p).equals(arr.get(a).getId() + ":" + id2)) {
//                                        Log.e("详情对比成功", goodskuParamQuery.get(p) + "          " + id1 + ":" + id2);
//                                    } else {
//                                        Log.e("详情对比失败", goodskuParamQuery.get(p) + "          " + id1 + ":" + id2);
//                                    }
//                                }
//                            }
//                        }
//                    }

//                    for(int k=0; k<parmQueryBean.getData().getGoodsSku().size();k++){
//                        goodskuParamQuery.add(parmQueryBean.getData().getGoodsSku().get(k).getParamQuery());
//                        for(int p=0;p<goodskuParamQuery.size();p++){
//                            if(goodskuParamQuery.get(p).equals(id1+":"+id2)){
//
//                                Log.e("详情对比成功",goodskuParamQuery.get(p)+"          "+id1+":"+id2);
//                            }else{
//                                Log.e("详情对比失败",goodskuParamQuery.get(p)+"          "+id1+":"+id2);
//                            }
//                        }
//                        Log.e("详情GoodsSku","========"+parmQueryBean.getData().getGoodsSku().get(k).getParamQuery()+"    "+id1+":"+id2);
//                        if(parmQueryBean.getData().getGoodsSku().get(k).getParamQuery().equals(id1+":"+id2)){
//                            bg2.clear();
////                          popup_layout_size.setText(arr.get(a).getValue());
//                            Log.e("详情GoodsSku","========"+parmQueryBean.getData().getGoodsSku().get(k).getParamQuery()+"    "+id1+":"+id2);
//                            Log.e("详情GoodsSku","========"+arr.get(a).getValue());
//                            for(int s=0;s<listid2.size();s++){
//                                if(listid2.get(s).equals(id1)){
//                                    bg2.remove(value2.get(s));
//                                }
//                            }
//
//                        }else{
//                            for(int s=0;s<listid2.size();s++){
//                                if(listid2.get(s).equals(id1)){
//
//                                }else{
//                                    bg2.add(value2.get(s));
//                                    Log.e("详情bg2","bg2========"+bg2);
//                                }
//                            }
//                        }
//
//                        adapter2.setCurr(bg2);
//                        adapter2.notifyDataSetChanged();
//                    }

                }
                for(int u=0;u<value2.size();u++) {
                    if (arr.get(a).getValue().equals(value2.get(u))) {
                        ArrayList<String> valuelist=new ArrayList<String>();
                        valuelist.add(arr.get(a).getId());
                        for (int k = 0; k < parmQueryBean.getData().getGoodsSku().size(); k++) {
                            goodskuParamQuery.add(parmQueryBean.getData().getGoodsSku().get(k).getParamQuery());
                            for (int p = 0; p < goodskuParamQuery.size(); p++) {
                                bg2.clear();

                                for(int w=0;w<valuelist.size();w++) {

                                    if (goodskuParamQuery.get(p).equals(id1+ ":"+valuelist.get(w) )) {

                                        Log.e("详情对比成功", goodskuParamQuery.get(p) + "          " + id1+ ":"+valuelist.get(w));

                                    } else {

                                        if  (arr.get(a).getId().equals(valuelist.get(w))){
                                            bg2.add(arr.get(a).getValue());
                                            adapter2.setCurr(bg2);
                                            adapter2.notifyDataSetChanged();
                                        }
                                            Log.e("详情对比失败", goodskuParamQuery.get(p) + "          " +id1+ ":"+valuelist.get(w));

                                    }
                                }
                            }
                        }
                    }
                }
            }

            //改变选中状态
            adapter1.setCurrentItem(position);
            //通知ListView改变状态
            adapter1.notifyDataSetChanged();
            querid = id1+":"+id2;
            pa(querid);
        }
    });
    for(int a=0;a<arr.size();a++){
        if(arr.get(a).getValue().equals(value1.get(0))){
            Log.e("详情点击获取id",arr.get(a).getId()+"       "+value1.get(0));
            id1 = arr.get(a).getId();

            popup_layout_colour.setText(arr.get(a).getValue());
            if(parmQueryBean.getData().getGoodsSku().size()!=0){
                if(parmQueryBean.getData().getGoodsSku().get(0).equals(id1+":"+id2)){
                    popup_layout_colour.setText(arr.get(a).getValue());
                }
            }
        }
    }
    for(int a=0;a<arr.size();a++){
        if(arr.get(a).getValue().equals(value2.get(0))){
            Log.e("详情点击获取id",arr.get(a).getId()+"       "+value2.get(0));
            id2 = arr.get(a).getId();
            popup_layout_size.setText(arr.get(a).getValue());
            if(parmQueryBean.getData().getGoodsSku().size()!=0){
                if(parmQueryBean.getData().getGoodsSku().get(0).equals(id1+":"+id2)){
                    popup_layout_size.setText(arr.get(a).getValue());
                }
            }
        }
    }

    querid = id1+":"+id2;
    pa(querid);
    adapter2.setmMyItemclickListener(new Shoppingcart2popwinAdapter.MypopItemclickListener() {
        @Override
        public void itemclick(View view, int position) {
            lsid2.clear();
            bg1.clear();
            value2.get(position);
            for(int a=0;a<arr.size();a++){
                if(arr.get(a).getValue().equals(value2.get(position))){
                    Log.e("详情点击获取id",arr.get(a).getId()+"       "+value2.get(position));
                    popup_layout_size.setText(arr.get(a).getValue());
                    id2 = arr.get(a).getId();
                    lsid2.add(id2);

                    for (int t=0;t<lsid1.size();t++){
                        for (int y=0;y<lsid2.size();y++){
                            Log.e("详情id2对比","id对比========"+lsid1.get(t)+":"+lsid2.get(y));
                        }
                    }

                    Log.e("详情id对比","id对比========"+id1+":"+id2);
                    Log.e("详情GoodsSku","GoodsSku========"+parmQueryBean.getData().getGoodsSku());





//                 if(parmQueryBean.getData().getGoodsSku().get(k).getParamQuery().equals(id1+":"+id2)){
////                           popup_layout_size.setText(arr.get(a).getValue());
//                            Log.e("详情GoodsSku","arr.get(a).getValue()========"+arr.get(a).getValue());
//                        }else{
//                            for(int s=0;s<listid1.size();s++){
//                                if(listid1.get(s).equals(id2)){
//
//                                }else{
//                                    bg1.add(value1.get(s));
//                                    Log.e("详情bg1","bg1========"+bg1);
////                                    adapter1.setCurr(bg1);
////                                    adapter1.notifyDataSetChanged();
//                                }
//                            }
//                        }

                }
                for(int u=0;u<value1.size();u++) {
                    if (arr.get(a).getValue().equals(value1.get(u))) {
                        ArrayList<String> valuelist=new ArrayList<String>();
                        valuelist.add(arr.get(a).getId());
                        for (int k = 0; k < parmQueryBean.getData().getGoodsSku().size(); k++) {
                            goodskuParamQuery.add(parmQueryBean.getData().getGoodsSku().get(k).getParamQuery());
                            for (int p = 0; p < goodskuParamQuery.size(); p++) {
                                bg1.clear();
                                for(int w=0;w<valuelist.size();w++) {

                                    if (goodskuParamQuery.get(p).equals(valuelist.get(w) + ":" + id2)) {
                                        Log.e("详情对比成功", goodskuParamQuery.get(p) + "          " + valuelist.get(w)+ ":" + id2);
                                    } else {
                                        if  (arr.get(a).getId().equals(valuelist.get(w))){
                                            bg1.add(arr.get(a).getValue());
                                            adapter1.setCurr(bg1);
                                            adapter1.notifyDataSetChanged();
                                        }
                                        Log.e("详情对比失败", goodskuParamQuery.get(p) + "          " +valuelist.get(w)+ ":" + id2);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            //改变选中状态
            adapter2.setCurrentItem(position);
            //通知ListView改变状态
            adapter2.notifyDataSetChanged();

        }
    });
//    for(int a=0;a<arr.size();a++){
//        for(int u=0;u<value2.size();u++) {
//            if (arr.get(a).getValue().equals(value2.get(u))) {
//                for (int k = 0; k < parmQueryBean.getData().getGoodsSku().size(); k++) {
//                    goodskuParamQuery.add(parmQueryBean.getData().getGoodsSku().get(k).getParamQuery());
//                    for (int p = 0; p < goodskuParamQuery.size(); p++) {
//                        if (goodskuParamQuery.get(p).equals(id1 + ":" + arr.get(a).getId())) {
//                            Log.e("详情对比成功", goodskuParamQuery.get(p) + "          " + id1 + ":" + id2);
//                        } else {
//
//                            Log.e("详情对比失败", goodskuParamQuery.get(p) + "          " + id1 + ":" + id2);
//                        }
//                    }
//                }
//            }
//        }
//    }
//    for (int i = 0; i < parmQueryBean.getData().getPropertys().size(); i++) {
//        Log.e("详情规格", parmQueryBean.getData().getPropertys().get(i) + "====adkgaoifdjaioodjiasdjiofjasidjf");
//        String data = String.valueOf(parmQueryBean.getData().getPropertys().get(i));
//        Log.e("详情规格", data + "====data");
//        String data1 = data.substring(1);
//        String data2 = data1.substring(0, data1.length() - 1);
//        Log.e("详情规格", data2 + "====data2");
//        String[] all = data2.split(",");
//        for (int a = 0; a < all.length; a++) {
//            Log.e("详情规格", all[i] + "====split");
//                    String na=all[i];
//                    String[] ss=na.split("=");
//                    for(int s = 0; s < na.length(); s++){
//                        Log.e("详情规格",ss[s]+"====splitssss");
//                    }
//        }
//    }


}catch (Exception e){

}
            }
        });
        querid = id1+":"+id2;
        pa(querid);
        popouplayout_event_addshoppingcart.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (parmQueryBean==null||parmQueryBean.getData().getList().size()==0){
                    Toast.makeText(ShoppingCartActivity.this,"请选择商品参数",Toast.LENGTH_LONG).show();
                }else {
                    Map<String,String>stringMap=new HashMap<String, String>();
                    stringMap.put("skuId",parmQueryBean.getData().getList().get(0).getId());
                    Log.e("TTTTTTTTTTTT1111",parmQueryBean.getData().getList().get(0).getId());
                    stringMap.put("count",count+"");
                    OkHttpUtils.post().params(stringMap).url(ApiManager.BASE_NIUPAI_URL+"users/addshoppingcart"+"?token="+ SPUtils.getInstance().getString(SPConstants.KEY_USER_TOKEN)+"&appId="+ AUniqueIdentifier.getDeviceId(ShoppingCartActivity.this))
                            .build().execute(new StringCallback() {
                        @Override
                        public void onError(Request request, Exception e) {

                        }

                        @Override
                        public void onResponse(String response) {
                            Log.e("hsdfsksdkfhuie",response);
                            try {
                                JSONObject obj=new JSONObject(response);
                                if(obj.getString("code").equals("10000")){
//                                    Intent intent=new Intent(ShoppingCartActivity.this,ShopCartActivity.class);
//                                    startActivity(intent);
                                    Toast.makeText(ShoppingCartActivity.this,obj.getString("msg"),Toast.LENGTH_SHORT).show();

                                }else{
                                }
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }
                        }
                    });
                }

            }
        });


//        for (int i = 0; i < namelist.size(); i++) {
//            Log.e("8888888888888888", namelist.get(i));
//            layout = new LinearLayout(this);
//            layout.setOrientation(LinearLayout.VERTICAL);
//            LinearLayout.LayoutParams parms= new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
//                    LinearLayout.LayoutParams.WRAP_CONTENT);
//            TextView TextView = new TextView(this);
//            parms.setMargins(0,10, 0, 0);
//            TextView.setText(namelist.get(i));
//            TextView.setLayoutParams(parms);
//            layout.addView(TextView);
//            cclinearLayout = new LinearLayout(this);
//            cclinearLayout.setOrientation(linearLayout.HORIZONTAL);
//            Log.e("77777777777777", propertysBeanmap.size() + "");
//            buttenlist = new ArrayList<>();
//            Map<String, List<YouhuiParticularsBean.DataBean.DetailPropergoryBean>> stringListMap = propertysBeanmap.get(i);
//            final List<YouhuiParticularsBean.DataBean.DetailPropergoryBean> arrnamelsit = stringListMap.get(namelist.get(i));
//            for (int k = 0; k < arrnamelsit.size(); k++) {
//                LinearLayout.LayoutParams parm= new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
//                        LinearLayout.LayoutParams.WRAP_CONTENT);
//                TextView button = new TextView(this);
//                button.setText("\t\t\t"+arrnamelsit.get(k).getValue()+"\t\t\t");
//                button.setBackgroundResource(R.drawable.text_red_bg_a_hui);
//                button.setTextColor(Color.rgb(98,98,98));
//                button.setTextSize(14);
//                button.setHeight(70);
//                button.setGravity(35);
//                parm.setMargins(10,10, 10, 10);
//                button.setLayoutParams(parm);
//                button.setTag(arrnamelsit.get(k).getId());
//                buttenlist.add(button);
//                final int finalK = k;
//                buttenlist.get(k).setOnClickListener(new View.OnClickListener() {
//                    @Override
//                    public void onClick(View v) {
//                        commodityid = arrnamelsit.get(finalK).getId();
//                        Log.e("889966",commodityid);
//
//                        OkHttpUtils.post().addParams("parmQuery",commodityid).url(ApiManager.BASE_NIUPAI_URL+typex+"/getGoodsSkuByParmQuery").build().execute(new StringCallback() {
//                            @Override
//                            public void onError(Request request, Exception e) {
//
//                            }
//
//                            @Override
//                            public void onResponse(String response) {
//                                Log.e("jb666",response);
//                                Gson gson=new Gson();
//                                parmQueryBean = gson.fromJson(response, parmQueryBean.class);
//
//                                List<parmQueryBean.DataBean.ListBean> parmQueryBeanlist=new ArrayList<>();
//                                parmQueryBeanlist.addAll(parmQueryBean.getData().getList());
//                                Log.e("fdsfsdfshfg",parmQueryBeanlist.size()+"");
//                                for (int i=0;i<parmQueryBeanlist.size();i++){
//                                    spuId = parmQueryBeanlist.get(i).getSpuId();
//                                    com.huifaapp.mall.bean.parmQueryBean.DataBean.ListBean listBean = parmQueryBeanlist.get(0);
//                                    if (parmQueryBeanlist.get(i).getSkuDetails()==""){
//
//                                    }else {
//                                        Picasso.with(ShoppingCartActivity.this)
//                                                .load(listBean.getSkuDetails())
//                                                .into(popup_layout_skuDetails);
//                                        Picasso.with(ShoppingCartActivity.this)
//                                                .load(parmQueryBeanlist.get(0).getSkuDetails())
//                                                .into(popup_layout_skuDetails);
//                                    }
//
//                                    popup_layout_skuDetailsskuPrice.setText(parmQueryBeanlist.get(i).getSkuPrice());
//                                    popup_layout_totalInventory.setText(parmQueryBeanlist.get(i).getTotalInventory());
//                                }
//
//
//
//                            }
//                        });
//
//
//
//                    }
//                });
//                cclinearLayout.addView(buttenlist.get(k));
//            }
//
//            layout.addView(cclinearLayout);
//            popouplayout_event_parameter_tyoe1.addView(layout);
//
//        }

        AmountView mAmountView = (AmountView) popuplayout_event.findViewById(R.id.amount_view);
        mAmountView.setGoods_storage(50);
        mAmountView.setOnAmountChangeListener(new AmountView.OnAmountChangeListener() {
            @Override
            public void onAmountChange(View view, int amount) {

                count=amount;
            }
        });
        event_imge.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(ShoppingCartActivity.this, "关闭尺码页", Toast.LENGTH_SHORT).show();
                mEventPopWindow.dismiss();
            }
        });

        popouplayout_event_purchase.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if (parmQueryBean==null||parmQueryBean.getData().getList().size()==0){
                    Toast.makeText(ShoppingCartActivity.this,"请选择商品参数",Toast.LENGTH_LONG).show();
                }else {
                    Intent intent=new Intent(ShoppingCartActivity.this,DetailsofPaymentActivity.class);
                    listSkuidCount.add(parmQueryBean.getData().getList().get(0).getId()+":"+count);
                    intent.putExtra("intent","xq");
                    intent.putExtra("listSkuidCount",listSkuidCount);
                    startActivity(intent);
                }

            }
        });

        mEventPopWindow.setFocusable(true);
        mEventPopWindow.setHeight(1300);
        mEventPopWindow.setBackgroundDrawable(new BitmapDrawable());
        WindowManager.LayoutParams lp = getWindow().getAttributes();
        lp.alpha = 0.4f;
        getWindow().setAttributes(lp);
        mEventPopWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {

            @Override
            public void onDismiss() {
                WindowManager.LayoutParams lp = getWindow().getAttributes();
                lp.alpha = 1f;
                getWindow().setAttributes(lp);
            }
        });
        popuplayout_event.setOnKeyListener(onEventKeyListener);
        onEventKeyListener1 = new View.OnKeyListener() {

            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                if (keyCode == KeyEvent.KEYCODE_BACK) {
                    dismiss();
                    return true;
                }

                return false;
            }
        };
        //设置各个控件的点击响应
        mEventPopWindow.setOutsideTouchable(true);
        //显示PopupWindow
        View rootview = LayoutInflater.from(ShoppingCartActivity.this).inflate(R.layout.activity_shoppingcart, null);
        mEventPopWindow.showAtLocation(rootview, Gravity.BOTTOM, 0, 0);
    }
private void pa(String querid){
    Log.e("详情", ApiManager.BASE_NIUPAI_URL+typex+"/getGoodsSkuByParmQuery"+"?parmQuery="+querid);
    OkHttpUtils.post().addParams("parmQuery",querid).url(ApiManager.BASE_NIUPAI_URL+typex+"/getGoodsSkuByParmQuery").build().execute(new StringCallback() {
        @Override
        public void onError(Request request, Exception e) {

        }

        @Override
        public void onResponse(String response) {
            Log.e("jb666",response);
            Gson gson=new Gson();
            parmQueryBean = gson.fromJson(response, parmQueryBean.class);
            if(parmQueryBean.getCode().equals("10000")) {
                List<parmQueryBean.DataBean.ListBean> parmQueryBeanlist = new ArrayList<>();
                parmQueryBeanlist.addAll(parmQueryBean.getData().getList());
                Log.e("fdsfsdfshfg", parmQueryBeanlist.size() + "");
                for (int i = 0; i < parmQueryBeanlist.size(); i++) {
                    spuId = parmQueryBeanlist.get(i).getSpuId();
                    com.huifaapp.mall.bean.parmQueryBean.DataBean.ListBean listBean = parmQueryBeanlist.get(0);
                    if (parmQueryBeanlist.get(i).getSkuDetails() == "") {

                    } else {
                        Picasso.with(ShoppingCartActivity.this)
                                .load(listBean.getSkuDetails())
                                .into(popup_layout_skuDetails);
                        Picasso.with(ShoppingCartActivity.this)
                                .load(parmQueryBeanlist.get(0).getSkuDetails())
                                .into(popup_layout_skuDetails);
                    }

                    popup_layout_skuDetailsskuPrice.setText(parmQueryBeanlist.get(i).getSkuPrice());
                    popup_layout_totalInventory.setText(parmQueryBeanlist.get(i).getTotalInventory());
                }
            }else{
                Toast.makeText(ShoppingCartActivity.this,parmQueryBean.getCode(),Toast.LENGTH_SHORT).show();
            }


        }
    });
}
    private void initView() {
        particulars_tab = (TabLayout) findViewById(R.id.particulars_tab);
        particulars_viewPager = (CustomViewPager)findViewById(R.id.particulars_viewPager);
        particulars_viewPager.setScanScroll(false);
        ptlm = (PullUpToLoadMore) findViewById(R.id.ptlm);
        shoppingCartactivity_coupon = (LinearLayout)findViewById(R.id.shoppingCartactivity_Coupon);
        shoppingCartactivity__event = (LinearLayout)findViewById(R.id.shoppingCartactivity__Event);
        youhuiParticulars_goodsName = (TextView) findViewById(R.id.youhuiParticulars_goodsName);
        youhuiParticulars_price = (TextView) findViewById(R.id.youhuiParticulars_price);
        youhuiParticulars_priceconPrice = (TextView) findViewById(R.id.youhuiParticulars_priceconPrice);
        youhuiParticulars_wlCommission = (TextView) findViewById(R.id.youhuiParticulars_wlCommission);
        youhuiParticulars_totalSales = (TextView) findViewById(R.id.youhuiParticulars_totalSales);
        youhuiParticulars_isFreePost = (TextView) findViewById(R.id.youhuiParticulars_isFreePost);
        youhuiParticulars_bannerTip = (ImageView) findViewById(R.id.youhuiParticulars_bannerTip);
        youhuiParticulars_bannerTip2 = (ImageView) findViewById(R.id.youhuiParticulars_bannerTip2);
        youhuiParticulars_wlCommission_g = (LinearLayout) findViewById(R.id.youhuiParticulars_wlCommission_g);
        ll_shoppingcart_qunhou = (LinearLayout) findViewById(R.id.ll_shoppingcart_qunhou);
        if (SPUtils.getInstance().getString(SPConstants.KEY_ISSTORE).equals("1")){
            youhuiParticulars_wlCommission_g.setVisibility(View.VISIBLE);
            ll_shoppingcart_qunhou.setVisibility(View.VISIBLE);
        }else {
            youhuiParticulars_wlCommission_g.setVisibility(View.GONE);
            ll_shoppingcart_qunhou.setVisibility(View.GONE);
        }
        shoppingCartactivity_include_tab = (LinearLayout) findViewById(R.id.shoppingCartactivity_include).findViewById(R.id.shoppingCartactivity_include_tab);
        shoppingCartactivity_include_tab_yure = (LinearLayout) findViewById(R.id.shoppingCartactivity_include).findViewById(R.id.shoppingCartactivity_include_tab_yure);

        if("".equals(Isspceial)||"null".equals(Isspceial)||null==Isspceial){
            shoppingCartactivity_include_tab.setVisibility(View.VISIBLE);
            shoppingCartactivity_include_tab_yure.setVisibility(View.GONE);
        }else{
        if(Isspceial.equals("预热中")){
            shoppingCartactivity_include_tab.setVisibility(View.GONE);
            shoppingCartactivity_include_tab_yure.setVisibility(View.VISIBLE);
        }else if(Isspceial.equals("立即抢购")){
            shoppingCartactivity_include_tab.setVisibility(View.VISIBLE);
            shoppingCartactivity_include_tab_yure.setVisibility(View.GONE);
        }}

        LinearLayout shoppingCartactivity_include_addCart= (LinearLayout) findViewById(R.id.shoppingCartactivity_include).findViewById(R.id.shoppingCartactivity_include_addCart);
        LinearLayout shoppingCartactivity_include_addCollect= (LinearLayout) findViewById(R.id.shoppingCartactivity_include).findViewById(R.id.shoppingCartactivity_include_addCollect);
        LinearLayout shoppingCartactivity_include_addService= (LinearLayout) findViewById(R.id.shoppingCartactivity_include).findViewById(R.id.shoppingCartactivity_include_addService);
        final ImageView iv_shoucang= (ImageView) findViewById(R.id.shoppingCartactivity_include).findViewById(R.id.iv_shoucang);
        final ImageView iv_shoucang_cg= (ImageView) findViewById(R.id.shoppingCartactivity_include).findViewById(R.id.iv_shoucang_cg);
        shoppingCartactivity_include_addService.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!isLogin(ShoppingCartActivity.this, true)) {
                    return;
                }
                Intent intent = new Intent(ShoppingCartActivity.this, com.huifaapp.mall.activity.Homefragment.WebActivity.class);
                intent.putExtra("url",ApiManager.KEFU);
                startActivity(intent);
            }
        });



//        if(flag){
//            iv_shoucang.setVisibility(View.GONE);
//            iv_shoucang_cg.setVisibility(View.VISIBLE);
//            Toast.makeText(ShoppingCartActivity.this,flag+"",Toast.LENGTH_SHORT).show();
//        }else{
//            iv_shoucang_cg.setVisibility(View.VISIBLE);
//            iv_shoucang.setVisibility(View.GONE);
//            Toast.makeText(ShoppingCartActivity.this,flag+"",Toast.LENGTH_SHORT).show();
//        }

        iv_shoucang_cg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                Toast.makeText(ShoppingCartActivity.this,flag+"",Toast.LENGTH_SHORT).show();
//                flag=true;
                iv_shoucang.setVisibility(View.VISIBLE);
                iv_shoucang_cg.setVisibility(View.GONE);
            }
        });
        shoppingCartactivity_include_addCollect.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Map<String,String>map=new HashMap<String, String>();
                map.put("token", SPUtils.getInstance().getString(SPConstants.KEY_USER_TOKEN));
                map.put("appId",AUniqueIdentifier.getDeviceId(ShoppingCartActivity.this));
                map.put("goodsId",shopid);
                Log.e("添加收藏接口",ADDEOLLECTURL+"?"+"token="+SPUtils.getInstance().getString(SPConstants.KEY_USER_TOKEN)+"&"+"appId="+AUniqueIdentifier.getDeviceId(ShoppingCartActivity.this)+"&"+"goodsId="+shopid);
                OkHttpUtils.post().params(map).url(ADDEOLLECTURL).build().execute(new StringCallback() {
                    @Override
                    public void onError(Request request, Exception e) {

                    }

                    @Override
                    public void onResponse(String response) {
                     Log.e("添加收藏",response);
                        Gson gson=new Gson();
                        AddeollectBean addeollectBean = gson.fromJson(response, AddeollectBean.class);
                        if (addeollectBean.getCode().equals("10000")){
                            iv_shoucang_cg.setVisibility(View.VISIBLE);
                            iv_shoucang.setVisibility(View.GONE);
                            Toast.makeText(ShoppingCartActivity.this,"添加收藏成功",Toast.LENGTH_LONG).show();
                        }else  if (addeollectBean.getCode().equals("10001")){
                            iv_shoucang.setVisibility(View.VISIBLE);
                            iv_shoucang_cg.setVisibility(View.GONE);
//                            Toast.makeText(ShoppingCartActivity.this,list.getMsg(),Toast.LENGTH_LONG).show();
                            Intent intent=new Intent(ShoppingCartActivity.this,LoginActivity.class);
                            startActivity(intent);
                        }else {
                            iv_shoucang.setVisibility(View.VISIBLE);
                            iv_shoucang_cg.setVisibility(View.GONE);
                            Toast.makeText(ShoppingCartActivity.this,list.getMsg(),Toast.LENGTH_LONG).show();
                        }
                    }
                });
            }
        });
        shoppingCartactivity_include_addCart.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(null ==  youhuiParticularsBean.getData().getPropertys() ||  youhuiParticularsBean.getData().getPropertys().size() ==0 ){
                    Map<String,String>stringMap=new HashMap<String, String>();
                    stringMap.put("skuId",youhuiParticularsBean.getData().getGoodsSku().get(0).getId());
                    Log.e("SKUID",youhuiParticularsBean.getData().getGoodsSku().get(0).getId());
                    stringMap.put("count",count+"");
                    stringMap.put("token", SPUtils.getInstance().getString(SPConstants.KEY_USER_TOKEN));
                    stringMap.put("appId",AUniqueIdentifier.getDeviceId(ShoppingCartActivity.this));
                    OkHttpUtils.post().params(stringMap).url(ApiManager.BASE_NIUPAI_URL+"users/addshoppingcart").build().execute(new StringCallback() {
                        @Override
                        public void onError(Request request, Exception e) {

                        }

                        @Override
                        public void onResponse(String response) {
                              Log.e("购物车图弹框数据",response);
                            try {
                                JSONObject object=new JSONObject(response);
                                if(object.getString("code").equals("10000")) {
                                    Toast.makeText(ShoppingCartActivity.this, "添加购物车成功！", Toast.LENGTH_SHORT).show();
                                }else   if(object.getString("code").equals("10001")) {
                                    Intent intent=new Intent(ShoppingCartActivity.this,LoginActivity.class);
                                    startActivity(intent);
                                }
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }

                        }
                    });
//                    Intent intent=new Intent(ShoppingCartActivity.this,ShopCartActivity.class);
//                    startActivity(intent);

                }else{
                    EventpopWindow();
                }





            }
        });
        ImageView  shoppingbutten_destroy= (ImageView) findViewById(R.id.shoppingbutten_destroy);
        youhuiParticulars_banner = (Banner) findViewById(R.id.youhuiParticulars_banner);
        shoppingbutten_destroy.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        shoppingbutten_share = (ImageView) findViewById(R.id.shoppingbutten_share);
        shoppingbutten_share.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!isLogin(ShoppingCartActivity.this, true)) {
                    return;
                }
                SharepopWindow();
            }
        });

        shoppingCartactivity_include_tab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                try {
                    if (!isLogin(ShoppingCartActivity.this, true)) {
                        finish();
                        return;
                    }
                    Log.e("propertys的长度",youhuiParticularsBean.getData().getPropertys().size()+"           "+youhuiParticularsBean.getData().getGoodsSku().get(0).getId());
                    if(null ==  youhuiParticularsBean.getData().getPropertys() ||  youhuiParticularsBean.getData().getPropertys().size() ==0 ){

                        Log.e("propertys的长度",listSkuidCount+"");
                        Intent intent=new Intent(ShoppingCartActivity.this,DetailsofPaymentActivity.class);
                        Log.e("propertys的长度","www");
                        listSkuidCount.add(youhuiParticularsBean.getData().getGoodsSku().get(0).getId()+":"+count);
                        Log.e("propertys的长度",listSkuidCount+"");
                        intent.putExtra("intent","xq");
                        intent.putExtra("listSkuidCount",listSkuidCount);
                        startActivity(intent);
                    }else{
                        Log.e("propertys的长度","aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
                        EventpopWindow();
                    }
                }catch (NullPointerException e){

                }
            }
        });
    }
    /**
     * 检查用户是否登录
     * @param context
     * @param isNeedToLoginView true 表示需要跳转登录界面   false 只检查用户是否登录
     * @return
     */
    public static boolean isLogin(Context context, boolean isNeedToLoginView){
        String token =  SPUtils.getInstance().getString(SPConstants.KEY_USER_TOKEN);

        if (!TextUtils.isEmpty(token)){
            return true;
        }
        if (isNeedToLoginView) {
            Intent intent = new Intent(context,LoginActivity.class);
            context.startActivity(intent);

            return false;
        }
        return false;
    }
    private void SharepopWindow() {
        View contentView = LayoutInflater.from(ShoppingCartActivity.this).inflate(R.layout.popuplayout_share, null);
        LinearLayout popuplayout_share_g= (LinearLayout) contentView.findViewById(R.id.popuplayout_share_g);
        LinearLayout popuplayout_share_weixing= (LinearLayout) contentView.findViewById(R.id.popuplayout_share_weixing);
        LinearLayout popuplayout_share_pengyouquan= (LinearLayout) contentView.findViewById(R.id.popuplayout_share_pengyouquan);
        LinearLayout popuplayout_share_QQ= (LinearLayout) contentView.findViewById(R.id.popuplayout_share_QQ);
        LinearLayout popuplayout_share_XL= (LinearLayout) contentView.findViewById(R.id.popuplayout_share_XL);
        LinearLayout popuplayout_share_fengxianLJ= (LinearLayout) contentView.findViewById(R.id.popuplayout_share_fengxianLJ);
        if (SPUtils.getInstance().getString(SPConstants.KEY_ISSTORE).equals("1")){
            popuplayout_share_g.setVisibility(View.VISIBLE);
        }else {
            popuplayout_share_g.setVisibility(View.GONE);
        }
        popuplayout_share_weixing.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                UMImage image = new UMImage(ShoppingCartActivity.this,list.getData().getPoster());//网络图片
                shareUrl("1",null, null,image);
            }
        });
        popuplayout_share_pengyouquan.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                UMImage image = new UMImage(ShoppingCartActivity.this,list.getData().getPoster());//网络图片
                shareUrl("2",null, null,image);
            }
        });
        popuplayout_share_QQ.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                UMImage image = new UMImage(ShoppingCartActivity.this,list.getData().getPoster());//网络图片
                shareUrl("3",null, null,image);
            }
        });
        popuplayout_share_XL.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                UMImage image = new UMImage(ShoppingCartActivity.this,list.getData().getPoster());//网络图片
                shareUrl("4",null, null,image);
            }
        });
        popuplayout_share_fengxianLJ.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ClipboardUtils.copyText(list.getData().getLink().getUrl());
                Toast.makeText(ShoppingCartActivity.this,"   复制粘贴成功！ ",Toast.LENGTH_SHORT).show();
            }
        });
        mSharePopWindow = new PopupWindow(contentView, ViewPager.LayoutParams.MATCH_PARENT, ViewPager.LayoutParams.WRAP_CONTENT, true);
        mSharePopWindow.setContentView(contentView);
        mSharePopWindow.setContentView(contentView);
        share_imge = (ImageView) contentView.findViewById(R.id.share_imge);
        share_imge.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mSharePopWindow.dismiss();
            }
        });
        mSharePopWindow.setFocusable(true);
        mSharePopWindow.setBackgroundDrawable(new BitmapDrawable());
        contentView.setOnKeyListener(onKeyListener);
        onShareKeyListener = new View.OnKeyListener() {

            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                if (keyCode == KeyEvent.KEYCODE_BACK) {
                    dismiss();
                    return true;
                }

                return false;
            }
        };
        mSharePopWindow.setOutsideTouchable(true);
        //显示PopupWindow
        View rootview = LayoutInflater.from(ShoppingCartActivity.this).inflate(R.layout.activity_shoppingcart, null);
        mSharePopWindow.showAtLocation(rootview, Gravity.BOTTOM, 0, 0);
    }

    /**
     * 分享链接
     */

    private void shareUrl(String type, String con, UMWeb web, UMImage image) {

        Log.v("shiran","-----------shareUrl()----------");


        UMShareListener umShareListener = new UMShareListener() {
            @Override
            public void onStart(SHARE_MEDIA share_media) {
//                if (dialog!=null&&!dialog.isShowing()) {
//                    dialog.show();
//                }
            }

            @Override
            public void onResult(SHARE_MEDIA share_media) {
                if (share_media == SHARE_MEDIA.WEIXIN) {
                    ToastUtils.showShortSafe("微信分享成功");
                    Contig.shar=1;
                } else if (share_media == SHARE_MEDIA.WEIXIN_CIRCLE) {
                    ToastUtils.showShortSafe("朋友圈分享成功");
                    Contig.shar=1;
                } else if (share_media == SHARE_MEDIA.QQ) {
                    ToastUtils.showShortSafe("QQ分享成功");
                    Contig.shar=1;
                } else if (share_media == SHARE_MEDIA.SINA) {
                    ToastUtils.showShortSafe("新浪微博分享成功");
                    Contig.shar=1;
                } else {
                    ToastUtils.showShortSafe("分享成功");
                    Contig.shar=1;

                }
            }

            @Override
            public void onError(SHARE_MEDIA share_media, Throwable throwable) {
                if (share_media == SHARE_MEDIA.WEIXIN) {
                    ToastUtils.showShortSafe("微信分享失败");

                } else if (share_media == SHARE_MEDIA.WEIXIN_CIRCLE) {
                    ToastUtils.showShortSafe("朋友圈分享失败");
                } else if (share_media == SHARE_MEDIA.QQ) {
                    ToastUtils.showShortSafe("QQ分享失败");
                }else if (share_media == SHARE_MEDIA.SINA) {
                    ToastUtils.showShortSafe("新浪分享失败");
                }else {
                    ToastUtils.showShortSafe("分享失败");

                }
            }

            @Override
            public void onCancel(SHARE_MEDIA share_media) {
                if (share_media == SHARE_MEDIA.WEIXIN) {
                    ToastUtils.showShortSafe("微信分享取消");

                } else if (share_media == SHARE_MEDIA.WEIXIN_CIRCLE) {
                    ToastUtils.showShortSafe("朋友圈分享取消");
                } else if (share_media == SHARE_MEDIA.QQ) {
                    ToastUtils.showShortSafe("QQ分享取消");
                }else if (share_media == SHARE_MEDIA.SINA) {
                    ToastUtils.showShortSafe("新浪微博分享取消");
                }else {
                    ToastUtils.showShortSafe("分享取消");

                }
            }
        };

  if ("1".equals(type)) {  //分享微信
            new ShareAction((Activity) this)
                    .setPlatform(SHARE_MEDIA.WEIXIN).
                    setCallback(umShareListener)
                    .withText(con)
                    .withMedia(image)
                    .share();

        } else
            if ("2".equals(type)) { //分享朋友圈

                new ShareAction((Activity) this).setPlatform(SHARE_MEDIA.WEIXIN_CIRCLE).
                        setCallback(umShareListener)
                        .withMedia(image)
                        .withText(con)
                        .share();


            }else
            if ("3".equals(type)) { //分享朋友圈

                new ShareAction((Activity) this).setPlatform(SHARE_MEDIA.QQ).
                        setCallback(umShareListener)
                        .withMedia(image)
                        .withText(con)
                        .share();


            }
            else
            if ("4".equals(type)) { //分享朋友圈

                new ShareAction((Activity) this).setPlatform(SHARE_MEDIA.SINA).
                        setCallback(umShareListener)
                        .withMedia(image)
                        .withText(con)
                        .share();


            }
    }

    private void LoadWebJDShare(){

        String url = ApiManager.PRODUCT_PRESEND+"?spuId="+shopid+"&token="+ SPUtils.getInstance().getString(SPConstants.KEY_USER_TOKEN)+"&appId="+ AUniqueIdentifier.getDeviceId(ShoppingCartActivity.this);

        Log.e("数据", "路径Share--" + url);
        HttpUtils http = new HttpUtils();
        //http://www.jhjvip.cn:8081/market/mobile/jd/index?
        http.send(HttpRequest.HttpMethod.POST, url, new RequestCallBack<String>() {
            @Override
            public void onLoading(long total, long current, boolean isUploading) {
//                  testTextView.setText(current + "/" + total);
                com.umeng.socialize.utils.Log.e("数据", "数据-------" + current + "/" + total);
            }

            //
            @Override
            public void onSuccess(ResponseInfo<String> responseInfo) {
//                    textView.setText(responseInfo.result);
                try {
                    com.umeng.socialize.utils.Log.e("数据123", "数据d-------" + responseInfo.result);
                    Gson gson = new Gson();
                    list = gson.fromJson(responseInfo.result, WebJDShare.class);
                    if(list.getCode().equals("10000")) {
                    }else{
//                        Toast.makeText(ShoppingCartActivity.this, list.getMsg(),Toast.LENGTH_SHORT).show();
                    }
                }catch (JsonSyntaxException e){
                    Toast.makeText(ShoppingCartActivity.this,"未知错误",Toast.LENGTH_LONG).show();
                }

            }

            @Override
            public void onStart() {
            }

            @Override
            public void onFailure(HttpException error, String msg) {
            }
        });
    }
    private void CouponpopWindow() {
        //设置contentView
        View contentView = LayoutInflater.from(ShoppingCartActivity.this).inflate(R.layout.popuplayout_coupon, null);
        tamll_popuplayout_reds_recyclerView = (RecyclerView) contentView.findViewById(R.id.tamll_popuplayout_reds_RecyclerView);
        accomplish = (LinearLayout) contentView.findViewById(R.id.accomplish);
        mPopWindow = new PopupWindow(contentView, ViewPager.LayoutParams.MATCH_PARENT, ViewPager.LayoutParams.WRAP_CONTENT, true);
        mPopWindow.setContentView(contentView);
        WindowManager.LayoutParams lp = getWindow().getAttributes();
        lp.alpha = 0.4f;
        getWindow().setAttributes(lp);
        mPopWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {

            @Override
            public void onDismiss() {
                WindowManager.LayoutParams lp = getWindow().getAttributes();
                lp.alpha = 1f;
                getWindow().setAttributes(lp);
            }
        });

        Map<String,String>map=new HashMap<>();
        map.put("appId",AUniqueIdentifier.getDeviceId(ShoppingCartActivity.this));
        map.put("token",SPUtils.getInstance().getString(SPConstants.KEY_USER_TOKEN));
        map.put("type","0");
        map.put("goodsId",shopid);
        Log.e("系统红包接口",INFOURL+"?appId="+AUniqueIdentifier.getDeviceId(ShoppingCartActivity.this)+"&token="+SPUtils.getInstance().getString(SPConstants.KEY_USER_TOKEN)+"&type="+"0"+"&goodsId="+shopid);

        OkHttpUtils.post().params(map).url(INFOURL).build().execute(new StringCallback() {
            @Override
            public void onError(Request request, Exception e) {

            }

            @Override
            public void onResponse(String response) {
                Gson gson=new Gson();
                Goods goods = gson.fromJson(response, Goods.class);
                Goods.DataBean.GoodInfoBean goodInfo = goods.getData().getGoodInfo();


            }
        });
        imge1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(ShoppingCartActivity.this, "领取优惠券", Toast.LENGTH_SHORT).show();
            }
        });
        accomplish.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(ShoppingCartActivity.this, "完成", Toast.LENGTH_SHORT).show();
                mPopWindow.dismiss();
            }
        });
        mPopWindow.setFocusable(true);
        mPopWindow.setBackgroundDrawable(new BitmapDrawable());

        // 然后再设置它的键监听器
        contentView.setOnKeyListener(onKeyListener);
        onKeyListener = new View.OnKeyListener() {

            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                if (keyCode == KeyEvent.KEYCODE_BACK) {
                    dismiss();
                    return true;
                }

                return false;
            }
        };
        //设置各个控件的点击响应
        mPopWindow.setOutsideTouchable(true);
        //显示PopupWindow
        View rootview = LayoutInflater.from(ShoppingCartActivity.this).inflate(R.layout.activity_shoppingcart, null);
        mPopWindow.showAtLocation(rootview, Gravity.BOTTOM, 0, 0);


    }

    private void initTab() {
        stringList = new ArrayList<>();
        stringList.add("商品介绍");
        stringList.add("规格参数");
        stringList.add("宝贝评价");
        fragmentList = new ArrayList<>();
        particularsIntroduceFragment = new ParticularsIntroduceFragment();
        specificationsFramgnet = new SpecificationsFramgnet();
        evaluateFragment = new EvaluateFragment();
        fragmentList.add(particularsIntroduceFragment);
        fragmentList.add(specificationsFramgnet);
        fragmentList.add(evaluateFragment);

        particulars_viewPager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int position) {
                return fragmentList.get(position);
            }

            @Override
            public int getCount() {
                return fragmentList.size();
            }

            @Override
            public CharSequence getPageTitle(int position) {
                return stringList.get(position);
            }

        });
        particulars_tab.setupWithViewPager(particulars_viewPager);
    }



}